package yf.mall.utils;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * mapper工具类
 * @author yxmds
 */
public final class MapperUtils {

    public static void addCriterion(Object c, String sql) {

        Class<?> generatedCriteriaCls = c.getClass().getSuperclass();
        Method addCriterion = null;
        try {
            addCriterion = generatedCriteriaCls.getDeclaredMethod("addCriterion", String.class);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
        if(addCriterion == null){
            return;
        }
        addCriterion.setAccessible(true);
        try {
            addCriterion.invoke(c, sql);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }

}
